// pages/answer/errorAnswer/index.js.js
import {IMG_PATH} from "../../../config/index"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentIndex:0,
    statusBarHeight:0,
    scrollTop:0,
    itemHeight:0,
    userinfo:{},
    IMG_PATH:IMG_PATH,
    errAnswer:[],
    contentHeight:'450rpx',
    allAnswer:[],
    titleUrl: `${IMG_PATH}/answer/wgzx.png`,
    bottomUrl: `${IMG_PATH}/answer/bot_cz.png`,
    leftFlowerUrl: `${IMG_PATH}/answer/lef_sz.png`,
    rightFlowerUrl: `${IMG_PATH}/answer/rig_sz.png`,
    hdzq: `${IMG_PATH}/answer/hdzq.png`,
    hdcw: `${IMG_PATH}/answer/hdcw.png`,
    showVideo:false,
    videoUrl:'',
    isAnimation: false, //动画是否正在执行
    isLeft: 1, //左右晃动,
    curLeft: 0,
  },
  backClick(){
    wx.navigateBack()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(app.globalData.answer)
    // console.log(app.globalData.errAnswer)
    // console.log(app.globalData.rightAnswer)
    var allAnswer=app.globalData.errAnswer.concat(app.globalData.rightAnswer)
    console.log(allAnswer);
    this.setData({
      statusBarHeight:wx.getSystemInfoSync()['statusBarHeight'],
      userinfo:wx.getStorageSync('userinfo'),
      // errAnswer:app.globalData.errAnswer,
      // rightAnswer:app.globalData.rightAnswer,
      allAnswer:allAnswer
    })
    let that=this
    wx.getSystemInfo({
      success: function (res) {
        let clientHeight = res.windowHeight;
        let clientWidth = res.windowWidth;
        let changeHeight = 750 / clientWidth;
        // console.log(changeHeight);
        let height = clientHeight * changeHeight;
        let contentHeight=height*0.55
        // console.log(contentHeight);
        var swiperHeight=Math.round(contentHeight/changeHeight)
        console.log(swiperHeight);
        that.setData({
          contentHeight: contentHeight+'rpx',
        });
    }})
    this.decorAnimation();
    let query = wx.createSelectorQuery();
            query.select('.swiper-item0').boundingClientRect(rect=>{
              console.log(rect);
              let height = rect.height;
              this.setData({
                itemHeight:height,
              })
            }).exec();
  },
  openVideoUrl(e){
console.log(e.target.dataset.url);
this.setData({
  videoUrl:e.target.dataset.url,
  showVideo:true
})
  },
  closeVideo(){
    this.setData({
      showVideo:false
    })
  },
  changeSwiper(e){
    console.log(e);
    
    this.setData({
      currentIndex:e.detail.current,
      scrollTop:0
    })
    // console.log(this.data.currentIndex);
    let query = wx.createSelectorQuery();
    console.log(`'.swiper-item${this.data.currentIndex}'`);
            query.select(`.swiper-item${this.data.currentIndex}`).boundingClientRect(rect=>{
              console.log(rect);
              let height = rect.height;
              this.setData({
                itemHeight:height,
              })
            }).exec();
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 装饰动画
   */
  decorAnimation() {
    this.data.isAnimation = true;
    this.animate('.rightimg', [{
        translateX: 0
      },
      {
        translateX: -200
      },
    ], 1000, function () {}.bind(this))
    this.animate('.leftimg', [{
        translateX: 0
      },
      {
        translateX: 200
      },
    ], 1000, function () {}.bind(this))
    this.decorAnimation1();
  },

  /**
   * 循环动画
   */
  decorAnimation1() {
    this.data.isLeft = -1 * this.data.isLeft
    this.animate(".bottomimg", [{
        translateX: this.data.curLeft
      },
      {
        translateX: this.data.isLeft * 20
      },
    ], 10000, function () {
      this.data.curLeft = this.data.isLeft * 20;
      if (this.data.isAnimation) {
        this.decorAnimation1();
      }
    }.bind(this))
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.data.isAnimation = true;
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.data.isAnimation = false;
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    this.data.isAnimation = false;
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})